/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.msg;

import org.rails.extjs.AbsBase;
import org.rails.extjs.ajax.IWait;
import org.rails.extjs.javascript.JavaScript;

public class SimpleWait implements IWait {
	
	protected String asName;
	protected String loadText = "Loading...";
	
	public SimpleWait(){
		super();
		asName = getClass().getSimpleName() + "_" + AbsBase.createRandom(6);
	}
	
	public SimpleWait(String loadText){
		super();
		asName = getClass().getSimpleName() + "_" + AbsBase.createRandom(6);
		this.loadText = loadText;
	}
	
//	@Override
	public JavaScript show() {
		return new JavaScript();
	}

//	@Override
	public JavaScript hide() {
		return new JavaScript("{0}.hide();",asName);
	}

//	@Override
	public JavaScript getWaitScript() {
		return new JavaScript("var {0}={1}",asName,MessageBox.wait(loadText, "", null).getScript());
	}

//	@Override
	public void setLoadText(String loadText) {
		this.loadText = loadText;		
	}

//	@Override
	public String getLoadText() {
		return loadText;
	}

//	@Override
	public JavaScript error() {
		return new JavaScript("alert('Status: ' + res.status + ' ' + res.statusText);").append(hide());
	}


}
